"""
A miniature wrapper for json encoding and decoding.

"""

import simplejson
json_encode = simplejson.dumps

def de_unicode_keys(input):
    if isinstance(input, dict):
        r = {}
        for k,v in input.iteritems():
            r[k.encode('ascii')] = de_unicode_keys(v)
        return r
    elif isinstance(input, list):
        for k, v in enumerate(input):
            input[k] = de_unicode_keys(v)
        return input
    else:
        return input

json_decode = lambda x: de_unicode_keys(simplejson.loads(x))
